﻿#########################################################################################################
####	Author: Rahul G. Babar																		 ####
####    Purpose: Use this PowerShell script to activate the site collection feature if it is not     ####
####             already activated. Edit the script for specific requriements.						 ####
#########################################################################################################

$siteCollectionUrl = read-host "Enter site collection Url (ex. http://sp2010server:1234/) "
$featureName = read-host "Enter site collection level feature folder name which you want to activate"
if(($siteCollectionUrl -ne $null) -and ($siteCollectionUrl -ne "") -and ($featureName -ne $null) -and ($featureName -ne ""))
{
	$siteCollection = Get-SPSite -Identity $siteCollectionUrl -ErrorAction SilentlyContinue
	if($siteCollection -ne $null)
	{		
		$webFeature = Get-SPFeature -Site $siteCollection | Where-object {$_.DisplayName -eq $featureName}	-ErrorAction SilentlyContinue	
		if($webFeature -ne $null)
		{
			write-host "$featureName feature is already activated at site collection $siteCollectionUrl." -foregroundcolor Green
			write-host
		}
		else
		{
			write-host "$featureName Feature is not activated, activating the same." -foregroundcolor Yellow
			write-host
			Enable-SPFeature -Identity $featureName -URL $siteCollectionUrl -Force
			write-host "$featureName feature activated at site collection $siteCollectionUrl." -foregroundcolor Green
			write-host
		}			
	}
	else
	{
		write-host "Could not find site collection at $siteCollectionUrl" -foregroundcolor Red
	}	
}
else
{
	write-error "Invalid site collection Url or feature name Entered."
}